define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'washing_record/index' + location.search,
                    table: 'washing_record',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                showExport: true,
                showToggle: false,
                showColumns: false,
                commonSearch: true,
                searchFormVisible: true,                
                searchFormTemplate: 'searchformtpl',
                queryParams: function (params) {
                    //这里可以追加搜索条件
                    var filter = JSON.parse(params.filter);
                    var op = JSON.parse(params.op);
                    if($("#username").val()){
                        filter.username = $("#username").val();
                        op.username = "like";
                    }

                    if($("#sid").val()){
                        filter.sid = $("#sid").val();
                        op.sid = "like";
                    }

                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                },
                columns: [
                    [
                        {field: 'id', title: __('ID')},
                        {field: 'sid', title:__('Sid')},
                        {field: 'nickname',title:__('Nickname')},
                        {field: 'add_time_text', title: __('Add_time')},

                        {field: 'into_time_text', title: __('Into_time')},
                        {field: 'leave_time_text', title: __('Leave_time')},

                        {field: 'states_text', title: __('State')}, 
                        {field: 'operate', title: __('操作'),  table: table, operate:false,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'ajax',
                                    text: '解锁',
                                    title: '解锁',
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-magic',
                                    url: 'washing_record/status',
                                    confirm: '确认解锁吗？',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                        // Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                }
                            ],
                            //formatter: Table.api.formatter.buttons
                            formatter: function (value, row, index) {
                                if(row.locked == 3){
                                    return Table.api.formatter.operate.call(this, value, row, index);
                                }
                                // else{
                                //     return Controller.api.formatter.locked(row.locked, row, index);
                                // }
                            }
                        }, 


                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});